		$(document).ready(function(){
			$("#criteria").keyup(queryViaEnter);
			$("#btnSearch").click(query);
			$("#cities").change(cityChange);
			initCities();
			var count = loadAmap(locations);
			$("#btnSearch").text(count);
		});

		function initCities() {
			var selObj = $("#cities");
			for (var i = 0; i < areas.length; i += 1) {
				var area = areas[i];
				var level = area.level;
				if(level > 2) {
					continue;
				}
				selObj.append("<option>" + area.name + "</option>");
			}
		}

		function queryViaEnter() {
			var e = window.event;
			if (e.keyCode == "13") {		
				var myCriteria = $.trim($("#criteria").val());
				query(myCriteria);
			}
		}

		function cityChange() {
			var text = $(this).children('option:selected').text();
			var myCriteria = text.substring(0, 2);
			query(myCriteria);
		}

		function query(myCriteria) {
			var count = searchAmap(myCriteria);
			$("#btnSearch").text(count);
		}